/*
 * @Author: szx
 * @Date: 2022-03-03 13:54:13
 * @LastEditTime: 2022-03-03 14:00:48
 * @Description:
 * @FilePath: \leetcode\100-199\101\101_2.js
 */
function TreeNode(val, left, right) {
    this.val = val === undefined ? 0 : val;
    this.left = left === undefined ? null : left;
    this.right = right === undefined ? null : right;
}

/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function (root) {
    if (!root) return false;
    const dfs = (left, right) => {
        if (left == null && right == null) return true;
        if (!left || !right || left.val != right.val) return false;
        return dfs(left.left, right.right) && dfs(left.right, right.left);
    };

    return dfs(root.left, root.right);
};
